<?php
namespace Home\Controller;
use Think\Controller;
class IndexController extends Controller {
    public function index(){
        //$this->show('<style type="text/css">*{ padding: 0; margin: 0; } div{ padding: 4px 48px;} body{ background: #fff; font-family: "微软雅黑"; color: #333;font-size:24px} h1{ font-size: 100px; font-weight: normal; margin-bottom: 12px; } p{ line-height: 1.8em; font-size: 36px } a,a:hover,{color:blue;}</style><div style="padding: 24px 48px;"> <h1>:)</h1><p>欢迎使用 <b>ThinkPHP</b>！</p><br/>版本 V{$Think.version}</div><script type="text/javascript" src="http://ad.topthink.com/Public/static/client.js"></script><thinkad id="ad_55e75dfae343f5a1"></thinkad><script type="text/javascript" src="http://tajs.qq.com/stats?sId=9347272" charset="UTF-8"></script>','utf-8');
        $this->display();
    }

    public function upload()
    {
		$upload = new \Think\Upload();// 实例化上传类
		$upload->maxSize = 3145728 ;// 设置附件上传大小
		$upload->exts = array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
		$upload->rootPath = './Public/uploads/register/'; // 设置附件上传根目录 
		//$upload->savePath = ''; // 设置附件上传（子）目录
		$upload->autoSub=false;
	// 上传文件
		$info=$upload->upload();
		if(!$info) 
		{
			// 上传错误提示错误信息
			$this->error($upload->getError());
		}
		else
		{
			// 上传成功
			return $info;
			//$this->success('上传成功！');
		}
	}

	function img()
	{
		$photoinfo=$this->upload();
		$filePath='./Public/Uploads/photo/';
		$oldFileName=$photoinfo['photo']['savename'];
		$oldFileFullName=$filePath."\\".$oldFileName;
    	$newFileName='thumb_'.$oldFileName;
    	$newFileFullName=$filePath."\\".$newFileName;

    		// $filePath='./Public/uploads/photo/';
    		// $photoinfo=$this->upload();
    		// $filePath=$photoinfo['photo']['rootPath'];
    		// $oldFileName=$photoinfo['photo']['savename'];
    		// $oldFileFullName=$filePath."\\".$oldFileName;
    		// $newFileName='thumb_'.$oldFileName;
    		// $newFileFullName=$filePath."\\"$newFileName;
    		//$userModel->photo=$photoinfo['photo']['savename'];
    		//$imgFile=$photoinfo['photo']['rootPath'].'\\'.$photoinfo['photo']['savename'];
    	$image=new \Think\Image();
    	$image->open($oldFileFullName);
    	$image->thumb(100,100)->save($newFileFullName);
    	return $newFileName;
    	
	}

    public function register()
    {
    	//用户民是否存在
    	// 口令是否正确，加密md5
    		$userModel=D('Users');
    		if($userModel->create())
    		{
    			if ($userModel->add()) 
    			{
    				$this->success('注册成功',U('Admin/Index/users'));
    			}
    			else
    			{
    				$this->error('注册失败');
    			}
    			//$this->error($userModel->getError());
    		}
    		else
    		{
    			$this->error($userModel->getError());

	    		// if ($_FILES['photo']['error']==0)//判断文件上传是否成功
	    		// {
	    		// 	$fileName=$this->img();
	    		// 	$userModel->photo=$fileName;//
	    		// }
	    		// if($userModel->add())
		    	// {
		    	// 	$this->success('用户注册成功！','users');
		    	// }
		    	// else
		    	// {    		
		    	// 	$this->error('用户注册失败！');
		    	// }
	    	}
    }
}